﻿//我的收藏夹 v2.1 - 于向东(冬雷,donar) 2000.12.12
var appBackground          = ''        //应用程序背景
var barBackground          = ''        //隐藏板背景
var barBorderWidth         = 8        //隐藏板边界宽度
var barBorderColor         = 'activeborder'  //隐藏板边界背景
var barWidth               = 140       //隐藏板宽度
var lineWidth              = 200       //设置数据宽度(菜单、窗口、Outlook栏的宽度)
var menuImage              = 'mybaby/bgbars.gif' //菜单背景图片
var color = new Array()            //设置各区域背景色
color['background']        = '#FFFFFF'  //工作区
color['bodyoutlook']       = 'buttonface'  //outlook项
color['headoutlook']       = 'InActiveCaption'  //outlook标题
color['headoutlooktext']   = 'InActiveCaptionText'  //outlook标题  'InActiveCaptionText' 
color['brightoutlook']     = 'ActiveCaption'  //outlook加亮 'ActiveCaption'  //
color['brightoutlooktext'] = 'CaptionText'  //outlook加亮  'CaptionText'
color['bodysheet']         = '#000000'  //window项  buttonface
color['headsheet']         = 'InActiveCaption'  //window标题
color['headsheettext']     = 'InActiveCaptionText'  //window标题
color['brightsheet']       = 'ActiveCaption'  //window加亮
color['brightsheettext']   = 'CaptionText'  //window加亮
color['menu']              = '#99CCFF'  //菜单背景色 menu

var about = '作者：冬雷 donar@126.com  2000.10.25' //关于
var dir = new Array(Array('收藏栏目', '收藏项目'))
var dragObj, dragActive, dx, dy
var zid = 0, curID, curOut, curItem, bodyHeight, menuStatus, outlookNum = 0, dst = new Array()

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "")
		document.cookie = curCookie
}
function getCookie(name) {
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1) return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function drag(obj) {
	if (event.button != 1 || !obj) return
	dragObj = obj
	dx = event.x - dragObj.style.pixelLeft
	dy = event.y - dragObj.style.pixelTop
	dragActive = true
}
function mouseMove() {
	if (typeof(hbar) == 'object') {
		if (event.x == 0) {hbar.style.zIndex = ++zid; hbar.style.display = ''}
		else if (event.x > hbar.offsetWidth) hbar.style.display = 'none'
	}
	var obj = event.srcElement
	if (obj.className == 'item') {
		if (curItem) curItem.className = 'item'
		if (obj.id) {
			if (curItem != obj) showChildDir(obj)
		} else {
			childdir.style.display = 'none'
		}
		curItem = obj
		curItem.className = 'curitem'
	} else if (obj == menu.children(0) && menuStatus) {
		subdir.style.display = ''
	} else if (obj.parentElement == menu && obj != menu.children(0)) {
		subdir.style.display = 'none'
		childdir.style.display = 'none'
	}
	if (!dragObj || !dragActive) return
	dragObj.style.left = event.x - dx
	dragObj.style.top = event.y - dy
}
function mouseUp() {
	dragActive = false
}
function mouseDown() {
	if (event.srcElement != menu.children(0)) {
		subdir.style.display = 'none'
		menuStatus = false
		childdir.style.display = 'none'
	}
}
function showChildDir(obj) {
	var id = obj.id.substring(5, obj.id.length)
	childdir.innerHTML = ''
	for (var i = 1; i < dir[id].length; i ++) childdir.innerHTML += (dir[id][i]) ? dir[id][i] + '<br />' : '<hr>'
	childdir.style.top = menu.offsetHeight + id * 20
	childdir.style.left = subdir.offsetWidth - 10
	childdir.style.display = ''
	childdir.style.zIndex = ++zid
	childdir.style.background = color['bodyoutlook']
}
function getFocus(id) {
	var obj = document.all['win_' + id]
	for (var i = 0; i < dir.length; i ++) {
		var o = document.all['win_' + i]
		if (o) {
			o.children(0).style.background = color['head' + o.className]
			o.children(0).style.color = color['head' + o.className + 'text']
			if (o.className == 'outlook' && obj.className == 'outlook') o.children(1).style.display = 'none'
		}
	}
	obj.children(1).style.display = ''
	obj.children(0).style.background = color['bright' + obj.className]
	obj.children(0).style.color = color['bright' + obj.className + 'text']
	obj.style.zIndex = ++zid
	curID = id
	status = dir[id][0]
}
function changestyle(i) {
	var obj = document.all['win_' + i]
	var oc0 = obj.children(0).style
	var oc1 = obj.children(1).style
	if (dst[i] == 0) {
		obj.className = 'sheet'
		oc0.background = color['headsheet']
		oc0.color = color['headsheettext']
		oc0.border = ''
		oc1.background = color['bodysheet']
		oc1.border = ''
		oc1.display = ''
		oc1.height = ''
		dst[i] = 1
		outlookNum --
	} else {
		obj.className = 'outlook'
		oc0.background = color['headoutlook']
		oc0.color = color['headoutlooktext']
		oc0.border='1 outset'
		oc1.background = color['bodyoutlook']
		oc1.border = '1 inset'
		oc1.display = 'none'
		oc1.height = bodyHeight
		dst[i] = 0
		outlookNum ++
	}
	reSize()
}
function showMenuBar() {
	return '<div id=menu class=menubar style="display:none;background:' + color['menu'] + ' url(' + menuImage + ')">'
		//+ '<a class=menu style="width:75" href="javascript:showSubMenu()">' + document.title + '</a>'
		//+ '<a class=menu style="width:65" href="javascript:setwin()">保存设置</a>'
		//+ '<a class=menu style="width:30" href="javascript:alert(about)">关于</a>'
		+ '</div>'
}
function showDirMenu() {
	var str = '<div id=subdir class=submenu style="display:none;left:0;top:' + (menu.offsetHeight - 2) + ';width:' + lineWidth + ';background:' + color['menu'] + ';">'
	for (var i = 0; i < dir.length; i ++)
		str += '<div id=subs_' + i + ' class=item onclick="getFocus(' + i + ')">' + dir[i][0] + '</div>'
	str +='<hr>'
		+ '<div class=item onclick="window.close()">关闭窗口</div>'
		+ '</div>'
	return str
}
function showChildMenu() {
	return '<div id=childdir class=submenu style="display:none;width:' + lineWidth + ';background:' + color['menu'] + ';"></div>'
}
function showDirBody() {
	for (var i = 0, str = ''; i < dir.length; i ++) {
		var typ = (dst[i] == 1) ? 'sheet' : 'outlook'
		str +='<div id=win_' + i + ' class=' + typ + ' style="width:' + lineWidth + ';left:' + ((i + 1) * 60) + ';top:' + ((i + 1) * 24 + menu.offsetHeight) + ';" onmousedown="getFocus(' + i + ')">'
			+ '<div class=head style="background:' + color['head' + typ] + ';color:' + color['head' + typ + 'text'] + ';' + ((typ == 'outlook') ? 'border:1 outset' : '') + '" onmousedown="drag(parentElement)" >' + dir[i][0] + ' >></div>'
			+ '<div class=body style="background:' + color['body' + typ] + ';' + ((typ == 'outlook') ? 'height:' + bodyHeight + ';border:1 inset;display:none;' : '') + '">'
		for (var j = 1; j < dir[i].length; j ++) str += (dir[i][j]) ? dir[i][j] + '<br />' : '<hr>'
		str +='</div>'
			+ '</div>'
	}
	return str
}
function showSubMenu() {
	if (subdir.style.display == '') {
		subdir.style.display = 'none'
		menuStatus = false
		childdir.style.display = 'none'
	} else {
		subdir.style.display = ''
		subdir.style.zIndex = ++zid
		menuStatus = true
	}
}
function sethbar(str) {
	document.write('<div id=hbar style="position:absolute;display:none;background:' + barBorderColor + ';left:0;top:0;width:' + barWidth + ';height:100%;border-right:2 outset;padding:' + barBorderWidth + ';"><div style="border:1 inset;height:100%;background:' + barBackground + '">' + str + '</div></div>')
}
function setHeight() {
	bodyHeight = document.body.clientHeight - menu.offsetHeight - outlookNum * 20
}
function reSize() {
	setHeight()
	if (typeof(hbar) == 'object') {
		hbar.style.height = document.body.clientHeight
	}
	if (bodyHeight > 0) {
		for (var i = 0; i < dir.length; i ++) {
			if (dst[i] != 1) document.all['win_' + i].children(1).style.height = bodyHeight
		}
	}
	if (dst[curID] == 1) {
		for (var i = dir.length - 1; i >= 0; i --) {
			if (dst[i] != 1) {
				document.all['win_' + i].children(1).style.display = ''
				break
			}
		}
	} else {
		if (outlookNum == 1) document.all['win_' + curID].children(1).style.display = ''
	}
}
function setwin() {
	var d = new Date()
	d.setTime(d.getTime() + 365 * 24 * 60 * 60 * 1000)
	for (var i = 0, tp = ''; i < dir.length; i ++) {
		tp += (dst[i] == 1) ? '1' : '0'
	}
	setCookie('winid', curID, d)
	setCookie('wintp', tp, d)
	alert('当前显示风格已保存！')
}
function create() {
	if (create.arguments.length > 0) dir = create.arguments
	var id = getCookie('winid')
	var tp = getCookie('wintp')
	if (!id || id < 0 || id > dir.length - 1) id = dir.length - 1
	if (!tp)  tp = ''
	for (var i = 0; i < dir.length; i ++) {
		dst[i] = (tp.charAt(i) == 1) ? 1 : 0
		if (tp.charAt(i) != 1) outlookNum ++
	}
	if (!document.title) document.title = '上赛场网站管理系统'
	document.body.bgColor = color['background']
	document.body.background = appBackground
	document.write(showMenuBar())
	setHeight()
	document.write(showDirMenu() + showChildMenu())
	document.write(showDirBody())
	getFocus(id)
	reSize()
	onresize = reSize
	document.onclick = mouseDown
	document.onmouseup = mouseUp
	document.onmousemove = mouseMove
	document.oncontextmenu = new Function('return(false)')
	document.onselectstart = new Function('return(false)')
}
/* about='我的收藏夹 (Ver 2.1)\n'
	+ '\n'
	+ '我不喜欢把某个 Internet 地址作为默认页，\n'
	+ '但每次打开浏览器，却又总不忍目睹空旷的\n'
	+ '大白页，于是就做了这么个小东东。\n'
	+ '\n'
	+ '您如果感兴趣，也同样可以用它建立自己的\n'
	+ '收藏夹页面。很简单的，只要按给定格式写\n'
	+ '入您自己的内容就可以了。\n'
	+ '\n'
	+ '——冬雷(donar@s211.inhe.net) 2000.12.12'
*/	
//收藏夹对象及函数
//sethbar(strHTMLs)     //建立隐藏板(参数为HTML字符串)
//create(arrFavorate)   //建立收藏夹(参数为一组数组，每个数组即为一个独立的项，其中第一个元素为该项标题)
